using System;
using System.Collections.Generic;
using System.Security.Principal;

namespace InfiniTec.DirectoryServices
{
    /// <summary>
    /// Provides strongly-typed access to the properties of an Active Directory contact.
    /// </summary>
    public class ActiveDirectoryContact: ActiveDirectoryPrincipal
    {
        /// <summary>
        /// Gets the resolve types.
        /// </summary>
        /// <returns></returns>
        protected override ResolveTypes GetResolveTypes()
        {
            return ResolveTypes.Contacts;
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveDirectoryContact"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="hint">The hint.</param>
        /// <param name="connection">The connection.</param>
        public ActiveDirectoryContact(string name, NameHint hint, Connection connection) : base(name, hint, connection)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveDirectoryContact"/> class.
        /// </summary>
        /// <param name="objectId">The object id.</param>
        /// <param name="connection">The connection.</param>
        public ActiveDirectoryContact(Guid objectId, Connection connection) : base(objectId, connection)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveDirectoryContact"/> class.
        /// </summary>
        /// <param name="baseItem">The base item.</param>
        public ActiveDirectoryContact(Item baseItem) : base(baseItem)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveDirectoryContact"/> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="connection">The connection.</param>
        public ActiveDirectoryContact(SecurityIdentifier identifier, Connection connection) : base(identifier, connection)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveDirectoryContact"/> class.
        /// </summary>
        /// <param name="name">The name of the element. This can be a distinguished name, nt4 account name, email address, legacy exchange distinguished name or a display name. In the latter case, Ambiguous name resolution is used to find the principal.</param>
        /// <param name="connection">The connection.</param>
        /// <remarks>
        /// This constructor is equivalent to the constructor <see cref="ActiveDirectoryPrincipal(string, NameHint, Connection)"/>.
        /// </remarks>
        public ActiveDirectoryContact(string name, Connection connection) : base(name, connection)
        {
            Initialize();
        }

        private void Initialize()
        {
            AddRequiredFields(SchemaMapping.UserSchema);
        }

        /// <summary>
        /// Gets or sets the country.
        /// </summary>
        /// <value>The country.</value>
        public string Country
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Country); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Country, value); }
        }

        /// <summary>
        /// Gets or sets the company.
        /// </summary>
        /// <value>The company.</value>
        public string Company
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Company); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Company, value); }
        }

        /// <summary>
        /// Gets or sets the department.
        /// </summary>
        /// <value>The department.</value>
        public string Department
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Department); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Department, value); }
        }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public string Description
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Description); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Description, value); }
        }

        /// <summary>
        /// Gets or sets the fax number.
        /// </summary>
        /// <value>The fax number.</value>
        public string FaxNumber
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.FaxNumber); }
            set { Properties.SetPropertyValue(WellknownProperties.User.FaxNumber, value); }
        }

        /// <summary>
        /// Gets or sets the first name.
        /// </summary>
        /// <value>The name of the first.</value>
        public string FirstName
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.FirstName); }
            set { Properties.SetPropertyValue(WellknownProperties.User.FirstName, value); }
        }

        /// <summary>
        /// Gets or sets the home phone.
        /// </summary>
        /// <value>The home phone.</value>
        public string HomePhone
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.HomePhone); }
            set { Properties.SetPropertyValue(WellknownProperties.User.HomePhone, value); }
        }

        /// <summary>
        /// Gets or sets the initials.
        /// </summary>
        /// <value>The initials.</value>
        public string Initials
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Initials); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Initials, value); }
        }

        /// <summary>
        /// Gets or sets the IP phone.
        /// </summary>
        /// <value>The IP phone.</value>
        public string IPPhone
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.IPPhone); }
            set { Properties.SetPropertyValue(WellknownProperties.User.IPPhone, value); }
        }

        /// <summary>
        /// Gets or sets the city.
        /// </summary>
        /// <value>The city.</value>
        public string City
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.City); }
            set { Properties.SetPropertyValue(WellknownProperties.User.City, value); }
        }

        /// <summary>
        /// Gets or sets the mail address.
        /// </summary>
        /// <value>The mail address.</value>
        public string MailAddress
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.MailAddress); }
            set { Properties.SetPropertyValue(WellknownProperties.User.MailAddress, value); }
        }

        /// <summary>
        /// Gets or sets the mobile phone.
        /// </summary>
        /// <value>The mobile phone.</value>
        public string MobilePhone
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Mobile); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Mobile, value); }
        }

        /// <summary>
        /// Gets the other fax numbers.
        /// </summary>
        /// <value>The other fax numbers.</value>
        public IList<string> OtherFaxNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherFaxNumbers);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherFaxNumbers);
            }
        }

        /// <summary>
        /// Gets the other home numbers.
        /// </summary>
        /// <value>The other home numbers.</value>
        public IList<string> OtherHomeNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherHomePhones);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherHomePhones);
            }
        }

        /// <summary>
        /// Gets the other IP phone numbers.
        /// </summary>
        /// <value>The other IP phone numbers.</value>
        public IList<string> OtherIPPhoneNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherIPPhones);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherIPPhones);
            }
        }

        /// <summary>
        /// Gets the other mobile phone numbers.
        /// </summary>
        /// <value>The other mobile phone numbers.</value>
        public IList<string> OtherMobilePhoneNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherMobile);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherMobile);
            }
        }

        /// <summary>
        /// Gets the other pager numbers.
        /// </summary>
        /// <value>The other pager numbers.</value>
        public IList<string> OtherPagerNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherPager);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherPager);
            }
        }

        /// <summary>
        /// Gets the other telephone numbers.
        /// </summary>
        /// <value>The other telephone numbers.</value>
        public IList<string> OtherTelephoneNumbers
        {
            get
            {
                Properties.EnsurePropertyExists(WellknownProperties.User.OtherTelephoneNumbers);
                return Properties.GetMultiValuedPropertyValue(WellknownProperties.User.OtherTelephoneNumbers);
            }
        }

        /// <summary>
        /// Gets or sets the pager number.
        /// </summary>
        /// <value>The pager number.</value>
        public string PagerNumber
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.PagerNumber); }
            set { Properties.SetPropertyValue(WellknownProperties.User.PagerNumber, value); }
        }

        /// <summary>
        /// Gets or sets the office.
        /// </summary>
        /// <value>The office.</value>
        public string Office
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Office); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Office, value); }
        }

        /// <summary>
        /// Gets or sets the postal code.
        /// </summary>
        /// <value>The postal code.</value>
        public string PostalCode
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.PostalCode); }
            set { Properties.SetPropertyValue(WellknownProperties.User.PostalCode, value); }
        }

        /// <summary>
        /// Gets or sets the last name
        /// </summary>
        /// <value>The name of the last.</value>
        public string LastName
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.LastName); }
            set { Properties.SetPropertyValue(WellknownProperties.User.LastName, value); }
        }

        /// <summary>
        /// Gets or sets the post office box.
        /// </summary>
        /// <value>The post office box.</value>
        public string PostOfficeBox
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.PostOfficeBox); }
            set { Properties.SetPropertyValue(WellknownProperties.User.PostOfficeBox, value); }
        }

        /// <summary>
        /// Gets or sets the state.
        /// </summary>
        /// <value>The state.</value>
        public string State
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.State); }
            set { Properties.SetPropertyValue(WellknownProperties.User.State, value); }
        }

        /// <summary>
        /// Gets or sets the street address.
        /// </summary>
        /// <value>The street address.</value>
        public string StreetAddress
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.StreetAddress); }
            set { Properties.SetPropertyValue(WellknownProperties.User.StreetAddress, value); }
        }

        /// <summary>
        /// Gets or sets the telephone number.
        /// </summary>
        /// <value>The telephone number.</value>
        public string TelephoneNumber
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.TelephoneNumber); }
            set { Properties.SetPropertyValue(WellknownProperties.User.TelephoneNumber, value); }
        }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string Title
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.Title); }
            set { Properties.SetPropertyValue(WellknownProperties.User.Title, value); }
        }

        /// <summary>
        /// Gets or sets the other web page.
        /// </summary>
        /// <value>The other web page.</value>
        public string OtherWebPage
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.OtherWebPage); }
            set { Properties.SetPropertyValue(WellknownProperties.User.OtherWebPage, value); }
        }

        /// <summary>
        /// Gets or sets the user principal name.
        /// </summary>
        /// <value>The name of the user principal.</value>
        public string UserPrincipalName
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.UserPrincipalName); }
            set { Properties.SetPropertyValue(WellknownProperties.User.UserPrincipalName, value); }
        }

        /// <summary>
        /// Gets or sets the web page.
        /// </summary>
        /// <value>The web page.</value>
        public string WebPage
        {
            get { return Properties.GetPropertyValue(WellknownProperties.User.WebPage); }
            set { Properties.SetPropertyValue(WellknownProperties.User.WebPage, value); }
        }
    }
}
